The code you have in events or inside runInParallel blocks will continue to execute while the current part of your program is paused.
pause Until
Pause the current part of the program until a condition becomes true.
pauseUntil(() => true)
Sometimes you need to wait in one part of a program for something to happen somewhere else in the program. This is done by pausing until some condition elsewhere becomes true. Such a condition could be a value you set in an event block or a function that returns a boolean .
Parameters
- condition: a boolean condition that restarts the program when it becomes
true. - timeOut: an optional paramenter which is a number of milliseconds to wait for the condition to become
true. The pause ends when the timeout has elapsed even if condition is stillfalse.
Examples
Timer in a parallel block
Make a 5 second timer by counting time in a parallel code section.
let msecs = 0
control.runInParallel(function () {
while (true) {
control.waitMicros(1000)
msecs += 1
}
})
pauseUntil(() => msecs > 5000)
Timer in a boolean function
Wait on a five second timer function.
function waitFiveSeconds() : boolean {
for (let i = 0; i < 5000; i++) {
control.waitMicros(1000)
}
return true
}
pauseUntil(() => waitFiveSeconds())